package com.fast.cron.servlet;

import com.fast.cron.db.dao.UserDao;
import com.fast.cron.db.entry.User;
import com.fast.cron.db.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * the servlet of index
 *
 * @author :leo.jie
 * @version :v1.0
 * @date :2018/9/30 15:27
 */
public class IndexServlet extends HttpServlet {
    private final UserDao userService = new UserService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        resp.setHeader("Content-type", "text/html;charset=UTF-8");
        resp.setCharacterEncoding("utf-8");
        resp.setStatus(HttpServletResponse.SC_OK);
        try {
            User user = userService.findOneUserByUsername("fast_cron");
            resp.getWriter().println("<h1>Hello World!</h1>");
            resp.getWriter().println(user.toString());
            resp.getWriter().println(user.getUserId());
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
